﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media;

namespace BugLister
{
    [ValueConversion(typeof(BugEntry.BugImportance), typeof(SolidColorBrush))]
    class ImportanceColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var importance = (BugEntry.BugImportance)value;
            Color c;
            switch (importance)
            {
                case BugEntry.BugImportance.Critical:
                    c = Colors.Red;
                    break;
                case BugEntry.BugImportance.Major:
                    c = Colors.Orange;
                    break;
                case BugEntry.BugImportance.Medium:
                    c = Colors.Yellow;
                    break;
                case BugEntry.BugImportance.Minor:
                    c = Colors.YellowGreen;
                    break;
                default:
                    c = Colors.White;
                    break;
            }
            return new SolidColorBrush(c);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Color color = ((SolidColorBrush)value).Color;
            BugEntry.BugImportance importance;
            if (color == Colors.Red)
                importance = BugEntry.BugImportance.Critical;
            else if (color == Colors.Orange)
                importance = BugEntry.BugImportance.Major;
            else if (color == Colors.Yellow)
                importance = BugEntry.BugImportance.Medium;
            else
                importance = BugEntry.BugImportance.Minor;
            
            return (importance);
        }
    }
}
